import { color } from "../config"
import { curveVector } from "../config/curve"
import * as THREE from "three"
import vertexShader from "../shaders/wall/vertex.glsl"
import fragmentShader from "../shaders/wall/frag.glsl"
interface sphereConfig {
    [key: string]: number
}
export class Ball {
    scene: THREE.Scene
    time: THREE.IUniform
    config: sphereConfig
    constructor(scene: THREE.Scene, time: THREE.IUniform) {
        this.scene = scene
        this.time = time
        this.config = {
            radius: 50,// — 球体半径，默认为1。
            widthSegments: 32,// — 水平分段数（沿着经线分段），最小值为3，默认值为32。
            heightSegments: 16,// — 垂直分段数（沿着纬线分段），最小值为2，默认值为16。
            phiStart: 0,// — 指定水平（经线）起始角度，默认值为0。。
            phiLength: Math.PI * 2,// — 指定水平（经线）扫描角度的大小，默认值为 Math.PI * 2。
            thetaStart: 0,// — 指定垂直（纬线）起始角度，默认值为0。
            thetaLength: Math.PI/2,// — 指定垂直（纬线）扫描角度大小，默认值为 Math.PI。

        }
        this.init()
    }
    init() {
        let arr = Object.values(this.config)
        const geometry = new THREE.SphereGeometry(...arr)

        const material = new THREE.ShaderMaterial({
            vertexShader,
            fragmentShader,
            uniforms: {
                u_color: {
                    value: new THREE.Color(color.ball)
                },
                u_time: this.time,
                u_height: {
                    value: this.config.radius
                },
                u_opacity: {
                    value: 0.5
                }
            },
            transparent: true,
            side: THREE.DoubleSide,
            depthTest: false
        })
        const mesh = new THREE.Mesh(geometry, material)
        let position=curveVector[0]
        mesh.position.set(position.start.x,position.start.y,position.start.z)
        // mesh.position.y = this.config.height / 2
        this.scene.add(mesh)
    }
}